﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--DXMETADATA start type="MetaCharset" --><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"><!--DXMETADATA end-->
    <meta http-equiv="X-UA-Compatible" value="IE=9" />

    <!--DXMETADATA start type="Literal" condition="helpversion:value=3" value="<meta name=""Microsoft.Help.SelfBranded"" content=""true"" />" --><!--DXMETADATA end-->
    <!--DXMETADATA start type="PageItemTitle" format="<title>%%PageItemTitle%%</title>" --><title>addCustomFunction Method</title><!--DXMETADATA end-->
    <!--DXMETADATA start type="ItemTitleNoQuotes" format="<meta name=""Title"" content=""%%ItemTitleNoQuotes%%""/>" --><!--DXMETADATA end-->
    
    <!--DXMETADATA start type="PackageLink" packagename="jquery" filetype="script" firstlinkattributes="id=""mshs_support_script"""--><script src="template/packages/jquery/script/default/jquery-1.11.3.min.js" type="text/javascript" id="mshs_support_script"></script><!--DXMETADATA end-->
    <!--DXMETADATA start type="PackageLink" packagename="jquery-ui" filetype="script"--><script src="template/packages/jquery-ui/script/default/jquery-ui-1.11.4.min.js" type="text/javascript"></script><!--DXMETADATA end-->
    <!--DXMETADATA start type="PackageLink" packagename="jquery-ui" filetype="css"--><link rel="stylesheet" type="text/css" href="template/packages/jquery-ui/css/default/jquery-ui-1.11.4.css"></link><!--DXMETADATA end-->
    <!--DXMETADATA start type="TemplateSettingsJson" format="<script type=""text/javascript"">var Innovasys=(Innovasys||{});$.extend(true,Innovasys,{settings:{isHideBodyDuringLoadDisabled:true,dynamictoc:{isEnabled:true},inthistopic:{isSupported:true},dynamicstyles:{isDynamicWordWrapEnabled:true}}},{settings:%%TemplateSettingsJson%%});</script>" --><script type="text/javascript">var Innovasys=(Innovasys||{});$.extend(true,Innovasys,{settings:{isHideBodyDuringLoadDisabled:true,dynamictoc:{isEnabled:true},inthistopic:{isSupported:true},dynamicstyles:{isDynamicWordWrapEnabled:true}}},{settings:{"dynamictoc":{"initialNodeId":"n3625","initialNodeContainer":"c56","isResizable":true},"inthistopic":{"isEnabled":true},"currentLocale":"-","isFrameless":true,"navigationKind":"inpage","versions":{"locale":{"currentId":"-"}}}});</script><!--DXMETADATA end-->
    <!--DXMETADATA start type="PackageLink" packagename="light" filetype="css"--><link rel="stylesheet" type="text/css" href="template/packages/light/css/dynamic-toc.css"></link><!--DXMETADATA end-->
    <!--DXMETADATA start type="PackageLink" packagename="plugins-javascript" filetype="css"--><link rel="stylesheet" type="text/css" href="template/packages/plugins-javascript/css/default/jquery-plugins.css"></link><!--DXMETADATA end-->
    <!--DXMETADATA start type="PackageLink" packagename="core-javascript" filetype="css" firstlinkattributes=" data-mshv2-stylesheet=""/template/packages/core-javascript/dx.javascript.mshv2.css"" data-mshv1-stylesheet=""/template/packages/core-javascript/dx.javascript.mshv1.css"" data-responsive-mobile=""template/packages/core-javascript/dx.javascript.mobile.css"" data-responsive-tablet=""template/packages/core-javascript/dx.javascript.tablet.css"""--><link rel="stylesheet" type="text/css" href="template/packages/core-javascript/css/dx.javascript.css"  data-mshv2-stylesheet="/template/packages/core-javascript/dx.javascript.mshv2.css" data-mshv1-stylesheet="/template/packages/core-javascript/dx.javascript.mshv1.css" data-responsive-mobile="template/packages/core-javascript/dx.javascript.mobile.css" data-responsive-tablet="template/packages/core-javascript/dx.javascript.tablet.css"></link><!--DXMETADATA end-->
    <!--DXMETADATA start type="PackageLink" packagename="plugins-javascript" filetype="script"--><script src="template/packages/plugins-javascript/script/default/jquery-plugins.min.js" type="text/javascript"></script><!--DXMETADATA end-->
    <!--DXMETADATA start type="PackageLink" packagename="core-javascript" filetype="script"--><script src="template/packages/core-javascript/script/dx.javascript.min.js" type="text/javascript"></script><!--DXMETADATA end-->
    
    <!--DXMETADATA start type="TopicId" format="<meta name=""Microsoft.Help.Id"" content=""%%TopicId%%""/>" --><meta name="Microsoft.Help.Id" content="SpreadJS~GC.Spread.Sheets.Worksheet~addCustomFunction"/><!--DXMETADATA end-->
    <!--DXMETADATA start type="Synopsis" StripHtmlTags="True" MaxLength="250" format="<meta name=""Description"" content=""%%Synopsis%%"" />"--><meta name="Description" content="Adds a custom function." /><!--DXMETADATA end-->
    <!--DXMETADATA start type="TocParentId" format="<meta name=""Microsoft.Help.TocParent"" content=""%%TocParentId%%""/>" --><meta name="Microsoft.Help.TocParent" content="SpreadJS~GC.Spread.Sheets.Worksheet_methods"/><!--DXMETADATA end-->
    <meta name="Microsoft.Help.ContentType" content="Reference" />
    <!--DXMETADATA start type="MshvKeywords" condition="helpversion:value=3" --><!--DXMETADATA end-->
    <!--DXMETADATA start type="MshvMetaTags" condition="helpversion:value=3" --><!--DXMETADATA end-->
    <!--DXMETADATA start type="Help3CatalogLocale" condition="helpversion:value=3" format="<meta name=""Microsoft.Help.Locale"" content=""%%Help3CatalogLocale%%"" />"--><!--DXMETADATA end-->
    <!--DXMETADATA start type="Help3CatalogLocale" condition="helpversion:value=3" format="<meta name=""Microsoft.Help.TopicLocale"" content=""%%Help3CatalogLocale%%"" />"--><!--DXMETADATA end-->
    <!--DXMETADATA start type="Stylesheets" --><link rel="stylesheet" type="text/css" href="stylesheets/hs-simpletab.css"></link><!--DXMETADATA end-->
    <!--DXMETADATA start type="StylePropertyValues" format="<style>%%StylePropertyValues%%</style>" --><style>.i-is-new .i-page-title-text::after, ul#i-dt-root li.i-is-new>a::after { content: "New" }
</style><!--DXMETADATA end-->
    <!--DXMETADATA start type="Scripts" --><!--DXMETADATA end-->
    <!--DXMETADATA start type="DesignTime"--><!--DXMETADATA end-->
    <!--DXMETADATA start type="Scrap" condition="communityenabled" name="_COMMUNITY_PROPERTIES" --><!--DXMETADATA end -->
    <!--DXMETADATA start type="CustomHeadContent" --><link rel="stylesheet" type="text/css" href="template/packages/core-web/css/SP.css">
<script type="text/javascript">
var currentHeader = function() {
    return "spjs";
}
</script>
<script src="template/packages/core-web/script/topNavigation.js"></script>
<script async="" src="https://www.googletagmanager.com/gtm.js?id=GTM-WT462SJ"></script>
<script>
        (function (w, d, s, l, i) {
            w[l] = w[l] || [];
            w[l].push({
                'gtm.start': new Date().getTime()
                , event: 'gtm.js'
            });
            var f = d.getElementsByTagName(s)[0]
                , j = d.createElement(s)
                , dl = l != 'dataLayer' ? '&l=' + l : '';
            j.async = true;
            j.src = 'https://www.googletagmanager.com/gtm.js?id=' + i + dl;
            f.parentNode.insertBefore(j, f);
        })(window, document, 'script', 'dataLayer', 'GTM-WT462SJ');
    </script>
<!--DXMETADATA end-->
</head>

<body>
    <div id="i-before-header-content" class="i-before-header-content">
        
    </div>

    <div id="i-header-container">
        <div id="i-header-content" class="i-header-content i-content-width-container">
            <!--DXMETADATA start type="LogoImage" --><!--DXMETADATA end-->
            <div class="i-project-title"><!--DXMETADATA start type="ProjectTitle" -->SpreadJS Documentation<!--DXMETADATA end--></div>
            <div class="i-search-container">
                <!--DXMETADATA start type="outputfileextension" format="<form action=""websearch%%outputfileextension%%"">" --><form action="websearch.html"><!--DXMETADATA end-->
                <input id="i-search" name="query"/>
                <input type="submit" id="i-search-button" value=""/>
                <!--DXMETADATA start type="Literal" value="</form>" --></form><!--DXMETADATA end-->
            </div>
            <!--DXMETADATA start type="outputfileextension" format="<a id=""i-index-button"" href=""webindex%%outputfileextension%%""></a>" --><a id="i-index-button" href="webindex.html"></a><!--DXMETADATA end-->
        </div>
    </div>
    
    <div class="i-content-width-container"><div class="i-busy-overlay"></div></div>

    <div id="i-breadcrumbs-outer-container" class="i-content-width-container"><!--DXMETADATA start type="Breadcrumbs" scrap="_BREADCRUMBS" --><div class="i-breadcrumbs-container">
<a href="SpreadJS~GC.Spread.Sheets_namespace.html">GC.Spread.Sheets Namespace</a>
 / <a href="SpreadJS~GC.Spread.Sheets.Worksheet.html">Worksheet type</a>
 / addCustomFunction Method</div><!--DXMETADATA end --></div>

    <!--DXMETADATA start type="FilteredItemList" scrap="PARAMETERS_BUBBLES" namespace="parameter" source="Item" -->
<div id="fnPopupContent" class="i-popup-content">
The function to add.
</div>
<!--DXMETADATA end -->

    <div id="i-actions-outer-container" class="i-content-width-container">
        <div id="i-actions-container">
            <div id="i-actions-content" class="i-fixed-to-top">
                <!-- Spacing --> <span class="i-toggle-all-sections i-function-link">
                <label class="i-collapse-all"><!--DXMETADATA start type="Phrase" name="COLLAPSE_ALL" -->Collapse All<!--DXMETADATA end--></label>
                <label class="i-expand-all" style="display: none;"><!--DXMETADATA start type="Phrase" name="EXPAND_ALL" -->Expand All<!--DXMETADATA end--></label>
            </span><!--DXMETADATA start type="Literal" condition="communityenabled" value="%%scrap:name=_COMMUNITY_DROPDOWN%%" --><!--DXMETADATA end -->
                <div class="i-in-this-topic-container">
                    <span class="i-action-group-heading"><!--DXMETADATA start type="Phrase" Name="IN_THIS_TOPIC" -->In This Topic<!--DXMETADATA end--></span>
                </div>
            </div>
        </div>
    </div>

    <div id="i-toc-outer-container" class="i-content-width-container">
        <div id="i-toc-container">
            <div id="i-toc-content" class="i-fixed-to-top">
                <div class="i-toc-content-scroll-container">
                    <div id="i-dynamic-toc-container"><ul id="i-dt-root"></ul></div>
                </div>
            </div>
        </div>
    </div>

    <div id="i-body-content-container" class="i-content-width-container">
        <div id="i-body-content" class="i-body-content">
            <div class="i-page-title"><div class="i-page-title-text"><!--DXMETADATA start type="PageItemTitle" -->addCustomFunction Method<!--DXMETADATA end--></div></div>
            <div class="i-in-this-topic-container">
                <span class="i-action-group-heading"><!--DXMETADATA start type="Phrase" Name="IN_THIS_TOPIC" -->In This Topic<!--DXMETADATA end--></span>
            </div>
            <!--DXMETADATA start type="Description" source="Item" format="<div class=""i-description-content"">%%description%%</div>" --><div class="i-description-content">Adds a custom function.</div><!--DXMETADATA end -->
            <!--DXMETADATA start type="SyntaxSection" format="%%scrap:name=_COLLAPSIBLE_HEADER,idprefix=syntax,caption=$$Syntax$$%%%%SyntaxSection%%" --><div class="i-section-heading" id="i-syntax-section-heading"><span class="i-section-heading-icon"><!-- --></span><span class="i-section-heading-text">Syntax</span></div><div id="i-syntax-section-content" class="i-section-content">
      <div class="i-tab-container i-tab-container">
      <ul>
      
      <li class="i-filtered-content-Javascript_Usage"><a href="#i-syntax-Javascript_Usage">Javascript (Usage)</a></li>
    

      <li class="i-filtered-content-Javascript"><a href="#i-syntax-Javascript">Javascript (Specification)</a></li>
    

      </ul>
      
      <div id="i-syntax-Javascript_Usage" class="i-filtered-content-Javascript_Usage">
      <pre>var instance = new <a href="SpreadJS~GC.Spread.Sheets.Worksheet.html">GC.Spread.Sheets.Worksheet</a>(name);
var value; // Type: any
value = instance.addCustomFunction(fn);</pre>
      </div>
    

      <div id="i-syntax-Javascript" class="i-filtered-content-Javascript">
      <pre>function addCustomFunction( 
&nbsp;&nbsp;&nbsp;<i><a class="i-popup-link" id="fnPopupLink" data-popup-contentsource="#fnPopupContent" data-popup-showevent="click mouseenter">fn</a></i> : <a href="SpreadJS~GC.Spread.CalcEngine.Functions.Function.html">Function</a>
) : any;</pre>
      </div>
    

      </div>
    <!--DXMETADATA end -->
            <!--DXMETADATA start type="FilteredItemList" scrap="PARAMETERS_LIST" namespace="parameter" source="Item" filter="" NoCr="True" format="<h4 class=dxh4>$$ParameterList$$</h4>%%filtereditemlist%%" --><h4 class=dxh4>Parameters</h4><dl><dt><I>fn</I></dt>
<dd>The function to add.</dd></dl><!--DXMETADATA end -->

            <!--DXMETADATA start type="TaggedComment" source="Item" id="##RETURNS" format="<h4 class=dxh4>$$Return_Type$$</h4><div class=""i-returns-content"">%%comment%%</div></div>" blankformat="</div>" --></div><!--DXMETADATA end -->
            <!--DXMETADATA start type="FilteredItemList" scrap="EXCEPTION_LIST" namespace="exception" source="Item" filter="" designtime="true" format="%%replaceinquotes:value=false%%%%scrap:name=_COLLAPSIBLE_HEADER,idprefix=exceptions,caption=""$$Exceptions$$%%designlist:tagidentifier=##EXCEPTION,itemtype=Exception%%""%%%%filtereditemlist%%</div>" --><!--DXMETADATA end -->

            <a name="exampleBookmark"></a>
            <!--DXMETADATA start type="TaggedComment" source="Item" id="##EXAMPLEINTRO" format="%%replaceinquotes:value=false%%%%scrap:name=_COLLAPSIBLE_HEADER,idprefix=example,caption=""$$Example$$%%designlist:tagidentifier=##EXAMPLECODE,itemtype=Example%%""%%%%comment%%" --><div class="i-section-heading" id="i-example-section-heading"><span class="i-section-heading-icon"><!-- --></span><span class="i-section-heading-text">Example</span></div><div id="i-example-section-content" class="i-section-content">These examples create custom functions.<!--DXMETADATA end -->
            <!--DXMETADATA start type="FilteredItemList" scrap="EXAMPLEGROUP_LIST" namespace="ExampleGroup" source="Item" filter="type=inline" condition="content:content=""%%GroupExamples%%"",operator=""="",value=""True""" NoHeader="True" NoFooter="True" format="%%replaceinquotes:value=false%%%%taggedcomment:source=item,id=##EXAMPLEINTRO,blankformat=""%%scrap:name=_COLLAPSIBLE_HEADER,idprefix=example,caption=$$Example$$%%"",format= %%%%filtereditemlist%%</div>" blankformat="%%taggedcomment:source=item,id=##EXAMPLEINTRO,format=</div>%%" --><!--DXMETADATA end -->
            <!--DXMETADATA start type="FilteredItemList" scrap="INLINE_EXAMPLE" namespace="Example" source="Item" filter="type=inline" condition="content:content=""%%GroupExamples%%"",operator=""<>"",value=""True""" NoHeader="True" NoFooter="True" format="%%replaceinquotes:value=false%%%%taggedcomment:source=item,id=##EXAMPLEINTRO,blankformat=""%%scrap:name=_COLLAPSIBLE_HEADER,idprefix=example,caption=$$Example$$%%"",format= %%%%filtereditemlist%%</div>" blankformat="%%taggedcomment:source=item,id=##EXAMPLEINTRO,format=</div>%%" --> <div class="i-filtered-content-Javascript">
    
	<div class="i-tab-container">
	    <ul>
	        <li><a href="#i-tab-content-5d20774e-89f9-4546-ae23-d7bc9b9f4b18">Javascript</a></li>
	    </ul>
	    <div id="i-tab-content-5d20774e-89f9-4546-ae23-d7bc9b9f4b18" class="i-filtered-content-Javascript i-code"><pre><span style="color: #0000FF; ">function</span> FactorialFunction() {
    <span style="color: #0000FF; ">this</span>.name = <span style="color: #800000; ">&quot;FACTORIAL&quot;</span>;
    <span style="color: #0000FF; ">this</span>.maxArgs = 1;
    <span style="color: #0000FF; ">this</span>.minArgs = 1;
}
FactorialFunction.prototype = <span style="color: #0000FF; ">new</span> GC.Spread.CalcEngine.Functions.Function();
FactorialFunction.prototype.evaluate = <span style="color: #0000FF; ">function</span> () {
    <span style="color: #0000FF; ">var</span> result = 1, args = arguments;
    <span style="color: #0000FF; ">if</span> (args.length === 1 &amp;&amp; !isNaN(parseInt(args[0]))) {
        <span style="color: #0000FF; ">for</span> (<span style="color: #0000FF; ">var</span> i = 1; i &lt; args[0]; i++) {
            result = i * result;
        }
        <span style="color: #0000FF; ">return</span> result;
    }
    <span style="color: #0000FF; ">return</span> <span style="color: #800000; ">&quot;#VALUE!&quot;</span>;
}

<span style="color: #0000FF; ">var</span> factorial = <span style="color: #0000FF; ">new</span> FactorialFunction();
activeSheet.addCustomFunction(factorial);
activeSheet.getCell(0,0).formula(<span style="color: #800000; ">&quot;factorial(5)&quot;</span>);
<span style="color: #0000FF; ">var</span> name = activeSheet.getCustomFunction(<span style="color: #800000; ">&quot;factorial&quot;</span>);
alert(name);</pre></div>
	</div>
</div>
<div class="i-filtered-content-Javascript">
    
	<div class="i-tab-container">
	    <ul>
	        <li><a href="#i-tab-content-6ceaa4ab-33cb-4b91-b093-faf5bef46849">Javascript</a></li>
	    </ul>
	    <div id="i-tab-content-6ceaa4ab-33cb-4b91-b093-faf5bef46849" class="i-filtered-content-Javascript i-code"><pre><span style="color: #008000; ">// Type =factorial(5) in a cell to see the result
</span><span style="color: #0000FF; ">function</span> FactorialFunction() {
    <span style="color: #0000FF; ">this</span>.name = <span style="color: #800000; ">&quot;FACTORIAL&quot;</span>;
    <span style="color: #0000FF; ">this</span>.maxArgs = 1;
    <span style="color: #0000FF; ">this</span>.minArgs = 1;
}
FactorialFunction.prototype = <span style="color: #0000FF; ">new</span> GC.Spread.CalcEngine.Functions.Function();
FactorialFunction.prototype.evaluate = <span style="color: #0000FF; ">function</span> () {
    <span style="color: #0000FF; ">var</span> result = 1, args = arguments;
    <span style="color: #0000FF; ">if</span> (args.length === 1 &amp;&amp; !isNaN(parseInt(args[0]))) {
        <span style="color: #0000FF; ">for</span> (<span style="color: #0000FF; ">var</span> i = 1; i &lt; args[0]; i++) {
            result = i * result;
        }
        <span style="color: #0000FF; ">return</span> result;
    }
    <span style="color: #0000FF; ">return</span> <span style="color: #800000; ">&quot;#VALUE!&quot;</span>;
}

<span style="color: #0000FF; ">var</span> factorial = <span style="color: #0000FF; ">new</span> FactorialFunction();
activeSheet.addCustomFunction(factorial);</pre></div>
	</div>
</div>
<div class="i-filtered-content-Javascript">
    
	<div class="i-tab-container">
	    <ul>
	        <li><a href="#i-tab-content-1ce6bbf7-af6b-4bcc-a1b0-d1a9b883f424">Javascript</a></li>
	    </ul>
	    <div id="i-tab-content-1ce6bbf7-af6b-4bcc-a1b0-d1a9b883f424" class="i-filtered-content-Javascript i-code"><pre>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;SpreadJS V11 Development Sample&lt;/title&gt;
    &lt;link href=<span style="color: #800000; ">&quot;http://cdn.grapecity.com/spreadjs/hosted/css/gc.spread.sheets.excel2016colorful.12.0.0.css&quot;</span> rel=<span style="color: #800000; ">&quot;stylesheet&quot;</span> type=<span style="color: #800000; ">&quot;text/css&quot;</span>/&gt;
    &lt;script src=<span style="color: #800000; ">&quot;https://code.jquery.com/jquery-2.1.1.min.js&quot;</span> type=<span style="color: #800000; ">&quot;text/javascript&quot;</span>&gt;&lt;/script&gt;
    &lt;script type=<span style="color: #800000; ">&quot;text/javascript&quot;</span> src=<span style="color: #800000; ">&quot;http://cdn.grapecity.com/spreadjs/hosted/scripts/gc.spread.sheets.all.12.0.0.min.js&quot;</span>&gt;&lt;/script&gt;
    &lt;script type=<span style="color: #800000; ">&quot;text/javascript&quot;</span>&gt;
        <span style="color: #0000FF; ">function</span> CustomFunctionWithoutContext() {
            <span style="color: #0000FF; ">this</span>.name = <span style="color: #800000; ">&quot;FactorialAfterSum&quot;</span>;
            <span style="color: #0000FF; ">this</span>.maxArgs = 255;
            <span style="color: #0000FF; ">this</span>.minArgs = 1;
        }
        CustomFunctionWithoutContext.prototype = <span style="color: #0000FF; ">new</span> GC.Spread.CalcEngine.Functions.Function();
        CustomFunctionWithoutContext.prototype.description = <span style="color: #0000FF; ">function</span> () {
            <span style="color: #0000FF; ">return</span> {
                description: <span style="color: #800000; ">&quot;The function returns the factorial of the sum result&quot;</span>,
                parameters: [{
                    name: <span style="color: #800000; ">&quot;value&quot;</span>,
                    repeatable: <span style="color: #0000FF; ">true</span>,
                    optional: <span style="color: #0000FF; ">true</span>
                }],
            }
        }
        CustomFunctionWithoutContext.prototype.evaluate = <span style="color: #0000FF; ">function</span> () {
            <span style="color: #008000; ">//If the isContextSensitive return false.
</span>            <span style="color: #008000; ">//The arguments of evaluate will be the real function args.
</span>            <span style="color: #008000; ">//For example, =XXXFunction(1,2,3,4,5), the arguments will be 1,2,3,4,5.
</span>            <span style="color: #008000; ">//Hence, for this case, if you use =FactorialAfterSum(1,2,3), the arguments will be 1,2,3
</span>            <span style="color: #0000FF; ">if</span> (arguments.length &gt; 0) {
                <span style="color: #0000FF; ">var</span> sum = 0, factoral = 1;
                <span style="color: #008000; ">//Calc Sum
</span>                <span style="color: #0000FF; ">for</span> (<span style="color: #0000FF; ">var</span> i = 0; i &lt; arguments.length; i++) {
                    <span style="color: #0000FF; ">if</span> (!isNaN(arguments[i])) {
                        sum += parseInt(arguments[i]);
                    }
                }
                <span style="color: #008000; ">//Calc factoral
</span>                <span style="color: #0000FF; ">do</span> {
                    factoral *= sum;
                } <span style="color: #0000FF; ">while</span> (--sum &gt;= 1)
                <span style="color: #0000FF; ">return</span> factoral;
            }
            <span style="color: #0000FF; ">return</span> GC.Spread.CalcEngine.CalcError.parse(<span style="color: #800000; ">&quot;#Value!&quot;</span>);
        }





        <span style="color: #0000FF; ">function</span> CustomFunctionWithContext() {
            <span style="color: #0000FF; ">this</span>.name = <span style="color: #800000; ">&quot;FactorialAfterSum2&quot;</span>;
            <span style="color: #0000FF; ">this</span>.maxArgs = 255;
            <span style="color: #0000FF; ">this</span>.minArgs = 1;
        }
        CustomFunctionWithContext.prototype = <span style="color: #0000FF; ">new</span> GC.Spread.CalcEngine.Functions.Function();
        CustomFunctionWithContext.prototype.description = <span style="color: #0000FF; ">function</span> () {
            <span style="color: #0000FF; ">return</span> {
                description: <span style="color: #800000; ">&quot;The function returns the factorial of sum result&quot;</span>,
                parameters: [{
                    name: <span style="color: #800000; ">&quot;value&quot;</span>,
                    repeatable: <span style="color: #0000FF; ">true</span>,
                    optional: <span style="color: #0000FF; ">true</span>
                }],
            }
        }
        CustomFunctionWithContext.prototype.evaluate = <span style="color: #0000FF; ">function</span> () {
            <span style="color: #008000; ">//If the isContextSensitive return true.
</span>            <span style="color: #008000; ">//The first argument will be evaluateContext, used for function calculation.
</span>            <span style="color: #008000; ">//The following arguments will be the real function args.
</span>            <span style="color: #008000; ">//For example, =XXXFunction(1,2,3,4,5), the arguments will be context, 1, 2, 3, 4, 5.
</span>            <span style="color: #008000; ">//Hence, for this case, if customer use =FactorialAfterSum2(1,2,3), the arguments will be context, 1,2,3
</span>            <span style="color: #0000FF; ">if</span> (arguments.length &gt;= 1) {
                <span style="color: #0000FF; ">var</span> sum = 0, factoral = 1, context = arguments[0];
                <span style="color: #008000; ">//Calc Sum
</span>                <span style="color: #0000FF; ">for</span> (<span style="color: #0000FF; ">var</span> i = 1; i &lt; arguments.length; i++) {
                    <span style="color: #0000FF; ">if</span> (!isNaN(arguments[i]) &amp;&amp; arguments[i] !== <span style="color: #0000FF; ">null</span>) {
                        sum += parseInt(arguments[i]);
                    }
                }
                <span style="color: #008000; ">//Calc factoral
</span>                <span style="color: #0000FF; ">do</span> {
                    factoral *= sum;
                } <span style="color: #0000FF; ">while</span> (--sum &gt;= 1)
                <span style="color: #0000FF; ">return</span> factoral;
            }
            <span style="color: #0000FF; ">return</span> GC.Spread.CalcEngine.CalcError.parse(<span style="color: #800000; ">&quot;#Value!&quot;</span>);
        }
        CustomFunctionWithContext.prototype.isContextSensitive = <span style="color: #0000FF; ">function</span> () {
            <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">true</span>;
        }


        $(document).ready(<span style="color: #0000FF; ">function</span> () {
            <span style="color: #0000FF; ">var</span> spread = <span style="color: #0000FF; ">new</span> GC.Spread.Sheets.Workbook(document.getElementById(<span style="color: #800000; ">&quot;ss&quot;</span>));
            <span style="color: #0000FF; ">var</span> sheet = spread.getActiveSheet();
            sheet.addCustomFunction(<span style="color: #0000FF; ">new</span> CustomFunctionWithContext());
            sheet.addCustomFunction(<span style="color: #0000FF; ">new</span> CustomFunctionWithoutContext());

            sheet.setValue(0,0,1);
            sheet.setValue(1,0,2);
            sheet.setValue(2,0,3);
            sheet.setFormula(4,1,<span style="color: #800000; ">&quot;=FactorialAfterSum2(1,2,3)&quot;</span>);
            sheet.setFormula(5,1,<span style="color: #800000; ">&quot;=FactorialAfterSum2(A1,A2,A3)&quot;</span>);
        });
    &lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id=<span style="color: #800000; ">&quot;ss&quot;</span> style=<span style="color: #800000; ">&quot;width:70%;height:500px;border: 1px solid gray;font-size:10.5pt&quot;</span>&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></div>
	</div>
</div>
</div><!--DXMETADATA end -->
            <!--DXMETADATA start type="FilteredItemList" scrap="MENU_LINK" namespace="example" source="Item" filter="" NoHeader="True" NoFooter="True" format="%%scrap:name=_COLLAPSIBLE_HEADER,idprefix=example,caption=$$Example$$%%%%filtereditemlist%%</div>" --><!--DXMETADATA end -->
            <!--DXMETADATA start type="TaggedComment" source="Item" id="##REMARKS" format="%%scrap:name=_COLLAPSIBLE_HEADER,idprefix=remarks,caption=$$Remarks$$%%%%comment%%</div>" --><!--DXMETADATA end -->
            <!--DXMETADATA start type="FilteredItemList" scrap="BROWSER_COMPATIBILITY_LIST" namespace="Browser Compatibility" source="Item" filter="" condition="content:content=""%%IncludeBrowserCompatibility%%"",operator=""="",value=""True""" format="%%scrap:name=_COLLAPSIBLE_HEADER,idprefix=browsercompatibility,caption=$$Browser_Compatibility$$%%%%filtereditemlist%%</div>" blankformat="%%scrap:name=_COLLAPSIBLE_HEADER,idprefix=browsercompatibility,caption=$$Browser_Compatibility$$%%%%filtereditemlist%%</div>"--><!--DXMETADATA end -->
            <!--DXMETADATA start type="FilteredItemList" scrap="CATEGORIZED_LINKS" namespace="linkcategory" source="Item" filter="" NoHeader="True" NoFooter="True" format="%%replaceinquotes:value=false%%%%scrap:name=_COLLAPSIBLE_HEADER,idprefix=seealso,caption=""$$See_Also$$%%designlist:tagidentifier=##SEEALSO,itemtype=See Also%%""%%%%filtereditemlist%%</div>"--><div class="i-section-heading" id="i-seealso-section-heading"><span class="i-section-heading-icon"><!-- --></span><span class="i-section-heading-text">See Also</span></div><div id="i-seealso-section-content" class="i-section-content"><h4 class="dxh4">Reference</h4><p><a href="SpreadJS~GC.Spread.Sheets.Worksheet.html">Worksheet type</a>
</p>
</div><!--DXMETADATA end-->
            <div id="i-footer-content" class="i-footer-content">
                <!--DXMETADATA start type="Scrap" condition="communityenabled" name="_COMMUNITY_FOOTER" --><!--DXMETADATA end -->
<!--DXMETADATA start type="Variable" name="CopyrightNotice" format="<p>&nbsp;</p><p>&nbsp;</p><hr style=""height: 1px"" /><p>%%variable%%</p>" --><p>&nbsp;</p><p>&nbsp;</p><hr style="height: 1px" /><p><p>Copyright © 2019 GrapeCity, Inc. All rights reserved.</p>
<p><a href="https://www.grapecity.com/en/forums/winforms-edition" target="_blank">Product Support Forum</a> | <a href="javascript:window.print()">Print this page</a></p>
<ul class="social">
<li><a href="https://www.facebook.com/GrapeCityUS/" target="_blank" class="facebook">&nbsp;</a></li>
<li><a href="https://twitter.com/GrapeCityUS" target="_blank" class="twitter">&nbsp;</a></li>
<li><a href="https://www.linkedin.com/company/grapecity" target="_blank" class="linkedin">&nbsp;</a></li>
</ul>
</p><!--DXMETADATA end -->
<!--DXMETADATA start type="Variable" name="FeedbackLink" format="" --><a href="mailto:support@company.com?subject=Documentation Feedback: SpreadJS~GC.Spread.Sheets.Worksheet~addCustomFunction.html">Send comments</a> on this topic.<!--DXMETADATA end-->
            </div>
        </div>
    </div>
        
    <script type="text/javascript">
        $(function () {
            var documentInstance = new Innovasys.Content.Document(document.body);
            documentInstance.load();
        });
    </script>
</body>
</html>
